package cn.cdeden.system.controller.system;


import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.satoken.utils.LoginHelper;
import cn.cdeden.common.web.core.BaseController;
import cn.cdeden.knowledge.api.domain.RemoteResourceFollowService;
import cn.cdeden.knowledge.api.domain.RemoteResourceService;
import cn.cdeden.knowledge.api.domain.RemoteResourceTypeService;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceTypeVo;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceVo;
import cn.cdeden.system.api.model.LoginUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/sysResourceType")
public class SysResourceTypeController extends BaseController{
    @DubboReference
    private RemoteResourceTypeService remoteResourceTypeService;


    @GetMapping("/get-all")
//    @ApiOperation("查询全部的资源类型")
    public R<List<RemoteResourceTypeVo>> getAll() {
        return R.ok(remoteResourceTypeService.getAll());
    }

    @PostMapping("/add")
//    @Log("添加资源类型")
//    @ApiOperation("添加资源类型")
    public R add(@RequestBody RemoteResourceTypeVo sysResourceType) {
        List<RemoteResourceTypeVo> sysResourceTypeList = remoteResourceTypeService.getByName(sysResourceType);
        if (!sysResourceTypeList.isEmpty()) {
            return R.fail("406", "该资源类型已经存在！");
        }
        return R.ok(remoteResourceTypeService.save(sysResourceType));
    }

    @GetMapping("/edit/{id}")
//    @Log("编辑资源类型回显")
//    @ApiOperation("编辑资源类型回显")
    public R<RemoteResourceTypeVo> edit(@PathVariable("id") Integer resourceTypeId) {
        return R.ok(remoteResourceTypeService.getById(resourceTypeId));
    }

    @PutMapping("/edit")
//    @Log("编辑资源类型")
//    @ApiOperation("编辑资源类型")
    public R update(@RequestBody RemoteResourceTypeVo sysResourceType) {
        List<RemoteResourceTypeVo> sysResourceTypeList = remoteResourceTypeService.getByNameAndId(sysResourceType);
        if (!sysResourceTypeList.isEmpty()) {
            return R.fail("406","该资源类型已经存在！");
        }
        return R.ok(remoteResourceTypeService.updateById(sysResourceType));
    }

    @DeleteMapping("/delete/{id}")
//    @Log("删除资源类型")
//    @ApiOperation("删除资源类型")
    public R delete(@PathVariable("id") Integer resourceTypeId) {
        return R.ok(remoteResourceTypeService.removeById(resourceTypeId));
    }
}
